<template>
  <div ref="dom"></div>
</template>
<script>
import echarts from 'echarts'
import { on, off } from '@/libs/tools'
export default {
  props: {
    value: Object
  },
  data () {
    return {
      dom: null
    }
  },
  methods: {
    resize () {
      this.dom.resize()
    }
  },
  mounted () {
    this.$nextTick(() => {
      const option = {
        title: {
          text: '项目总统计表'
        },
        color: ['#19be6b', '#ff9900', '#fa541c', '#1890ff'],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            crossStyle: {
              color: '#999'
            }
          }
        },
        legend: {
          data: ['通过金额', '注册量', '申请量', '通过量', '拒件量']
        },
        xAxis: [
          {
            type: 'category',
            splitLine: {
              show: false
            },
            data: this.value.ctime
          }
        ],
        yAxis: [
          {
            type: 'value',
            name: '数量',
            min: 0,
            interval: 500,
            splitLine: {
              show: false
            }
          },
          {
            type: 'value',
            name: '金额',
            min: 0,
            interval: 50000,
            splitLine: {
              show: false
            },
            axisLabel: {
              formatter: '{value} 元'
            }
          }
        ],
        series: [
          {
            name: '通过金额',
            type: 'bar',
            yAxisIndex: 1,
            barWidth: '50',
            itemStyle: {
              color: '#5cadff'
            },
            data: this.value.tprice || []
          },
          {
            name: '注册量',
            type: 'line',
            smooth: true,
            lineStyle: {
              color: '#19be6b'
            },
            data: this.value.cpa || []
          },
          {
            name: '申请量',
            type: 'line',
            smooth: true,
            lineStyle: {
              color: '#ff9900'
            },
            data: this.value.req || []
          },
          {
            name: '通过量',
            type: 'line',
            smooth: true,
            lineStyle: {
              color: '#fa541c'
            },
            data: this.value.p || []
          },
          {
            name: '拒件量',
            type: 'line',
            smooth: true,
            lineStyle: {
              color: '#1890ff'
            },
            data: this.value.f || []
          }
        ]
      }
      this.dom = echarts.init(this.$refs.dom)
      this.dom.setOption(option)
      on(window, 'resize', this.resize)
    })
  },
  beforeDestroy () {
    off(window, 'resize', this.resize)
  }
}
</script>
<style>
</style>
